<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/tld/pageutil.tld" prefix="pu"%>
<%@taglib uri="/WEB-INF/tld/pageable.tld" prefix="pageable"%>
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c-rt"%>
<%@taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt-rt"%>

<c-rt:set var="tp" value="${pu:pageableTag('tpp', 10, 10)}"/>
<c-rt:if test="${empty param.keyword && empty param.status && empty param.approveStatus}">
<c-rt:set var="sas" value="${pu:queryByHql('from SupplierApply order by supplierID desc', null, tp)}"/>
</c-rt:if>
<c-rt:if test="${!empty param.keyword || !empty param.status || !empty param.approveStatus}">
<c-rt:if test="${!empty param.keyword}">
<c-rt:set var="keyword">%${param.keyword }%</c-rt:set>
${pu:reqSet('keywordHql', '(supplierID like ? or companyName like ? or companyNum like ?)') }
<c-rt:set var="params" value="${pu:addToList('paras', keyword)}"/>
<c-rt:set var="params" value="${pu:addToList('paras', keyword)}"/>
<c-rt:set var="params" value="${pu:addToList('paras', keyword)}"/>
</c-rt:if>


<c-rt:if test="${!empty param.status}">
${pu:reqSet('statusHql', empty keywordHql? 'status=?':' and status=?') }
<c-rt:set var="params" value="${pu:addToList('paras', param.status)}"/>
</c-rt:if>
<c-rt:if test="${!empty param.approveStatus}">
${pu:reqSet('approveStatusHql', empty keywordHql and empty statusHql?'approveStatus=?':' and approveStatus=?') }
<c-rt:set var="params" value="${pu:addToList('paras', param.approveStatus)}"/>
</c-rt:if>
<c-rt:set var="hql">
from SupplierApply where ${keywordHql } ${statusHql } ${approveStatusHql } order by createDate desc
</c-rt:set>

<c-rt:set var="sas" value="${pu:queryByHql(hql, params, tp)}"/>
</c-rt:if>
<br />
<h1>供应商管理
</h1>
<form name="searchSupplierForm" method="post">
<input type="hidden" name="iamlazy" id="iamlazy" value="list"/>
<table>
<tr>
<td>
关键字:<input type="text" value="${param.keyword }" name="keyword" id="keyword"/>
<select name="status">
	<option value="">供应商状态</option>
	${pu:reqSet('supplierStatuses', pu:get('com.yaodian100.core.menu.entity.Menu', 'Supplier.status'))}
	<c-rt:forEach items="${supplierStatuses.options}" var="status">
	<option value="${status.value.code }" <c-rt:if test="${param.status==status.value.code }">selected="selected"</c-rt:if>>${status.value.name }</option>
	</c-rt:forEach>
</select>
<select name="approveStatus">
	<option value="">审核状态</option>
	${pu:reqSet('supplierApproveStatuses', pu:get('com.yaodian100.core.menu.entity.Menu', 'Supplier.approveStatus'))}
	<c-rt:forEach items="${supplierApproveStatuses.options}" var="approveStatus">
	<option value="${approveStatus.value.code }" <c-rt:if test="${param.approveStatus==approveStatus.value.code }">selected="selected"</c-rt:if>>${approveStatus.value.name }</option>
	</c-rt:forEach>
</select>
</td><td><input type="button" id="searchSupplier" value="搜寻"/>
<input type="button" value="申请" onclick="location.href='<c-rt:url value="/supplierApply/page.do?iamlazy=toApply&AJAX=true&refreshZone=main"/>'"/>
</td>
</tr>
</table>
</form>

<table class="tb-1" width="100%">
		<thead>
			<tr>
				
				<th>供应商代码</th>
				<th>供应商营业执照注册号</th>
				<th>名称</th>
				<th>状态</th>
				<th>审核状态</th>
				<th>建立日期</th>
				<th></th>
			</tr>
		</thead>
		<tbody>
			<c-rt:forEach items="${sas}" var="sa" varStatus="rows_index">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">
					
					<td>${sa.supplierID }</td>
					<td>${sa.companyNum }</td>
					<td>${sa.companyName }</td>
					<td>${pu:menuOption('Supplier.status', pu:toString(sa.status)).name}</td>
					<td>${pu:menuOption('Supplier.approveStatus', pu:toString(sa.approveStatus)).name}</td>
					<td>${sa.createDate}</td>
					<td nowrap="nowrap">
					<c-rt:if test="${sa.status==0}">
					<input type="button" value="激活" onclick="if(confirm('are you sure?'))doAR('<%=application.getContextPath() %>/supplierApply/activate.do?AJAX=true&refreshZone=main&supplierID=${sa.supplierID }', 'main')"/>
					</c-rt:if>
					<c-rt:if test="${sa.status==1}">
					<input type="button" value="停用" onclick="if(confirm('are you sure?'))doAR('<%=application.getContextPath() %>/supplierApply/suspend.do?AJAX=true&refreshZone=main&supplierID=${sa.supplierID }', 'main')"/>
					</c-rt:if>
					<c-rt:if test="${sa.approveStatus==0}">
					<input type="button" value="核可" onclick="if(confirm('are you sure?'))doAR('<%=application.getContextPath() %>/supplierApply/approve.do?AJAX=true&refreshZone=main&supplierID=${sa.supplierID }', 'main')"/>
					</c-rt:if>
					<input type="button" value="编辑" onclick="location.href='<c-rt:url value="/supplierApply/page.do?iamlazy=toUpdate&supplierID=${sa.supplierID }"/>'"/>
					</td>
				</tr>
			</c-rt:forEach>
		</tbody>
	</table>
<c-rt:set var="url">
<%=application.getContextPath() %>/supplierApply/page.do?iamlazy=list
</c-rt:set>
<pageable:Pageable url="${url}" escapeparams="iamlazy,AJAX,refreshZone" parameter="" formname="supplierForm" key="tpp"></pageable:Pageable>
<script>
$(document).ready(function(){
	$('#searchSupplier').click(function(){
		$('iamlazy').attr('value', 'list');
		document.searchSupplierForm.action='<%=application.getContextPath() %>/supplierApply/page.do';
		document.searchSupplierForm.submit();
	});
});
</script>